//
// Created by Administrator on 2023/8/6.
//
#include <string>
#include <iostream>

using namespace std;

class Solution {
public:
    bool isCircularSentence(string sentence) {
        // 重要的性质 首尾不是空格
        // 先判断头尾是否相同
        if (*sentence.begin() != *(sentence.end() - 1)) return false;
        // 中间的话 需要找到空格 然后判断左右是否相同
        for (int i = 1; i < sentence.size() - 1; i++) {
            if (sentence[i] == ' ') {
                if (sentence[i - 1] != sentence[i + 1]) return false;
            }
        }
        return true;
    }
};

int main() {
    Solution solution;
    string sentence = "leetcode exercises sound delightful";
    cout << solution.isCircularSentence(sentence) << endl;
    return 0;

}